package cn.terminus.biz.customer.contractselldefyloaninfo;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.contractselldefyloaninfo.dto.*;
import cn.terminus.data.customer.contractselldefyloaninfo.dao.ContractSellDefyLoanInfoDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 贷款违约(ContractSellDefyLoanInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-07-21 11:18:14
 */
@Component
public class ContractSellDefyLoanInfoManager extends AbstractTerminusManager {
    @Autowired
    private ContractSellDefyLoanInfoDao contractSellDefyLoanInfoDao;

    public Integer add(ContractSellDefyLoanInfoNewDto dto) throws DataAccessException {
        try {
            return contractSellDefyLoanInfoDao.add(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyLoanInfoManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(ContractSellDefyLoanInfoEditDto dto) throws DataAccessException {
        try {
            return contractSellDefyLoanInfoDao.update(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyLoanInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractSellDefyLoanInfoResultDto> gets(ContractSellDefyLoanInfoGetsDto dto) throws DataAccessException {
        try {
            return contractSellDefyLoanInfoDao.gets(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyLoanInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractSellDefyLoanInfoResultDto> query(ContractSellDefyLoanInfoQueryDto dto) throws DataAccessException {
        try {
            return contractSellDefyLoanInfoDao.query(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyLoanInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(ContractSellDefyLoanInfoDeleteDto dto) throws DataAccessException {
        try {
            return contractSellDefyLoanInfoDao.delete(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyLoanInfoManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<ContractSellDefyLoanInfoResultDto> page(ContractSellDefyLoanInfoQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<ContractSellDefyLoanInfoResultDto> result = (Page<ContractSellDefyLoanInfoResultDto>) contractSellDefyLoanInfoDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), ContractSellDefyLoanInfoResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("ContractSellDefyLoanInfoManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer deleteWithContractId(Long id) throws DataAccessException {
        try {
            return contractSellDefyLoanInfoDao.deleteWithContractId(id);
        } catch (Exception e) {
            logger.error("ContractSellDefyLoanInfoManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
